import './tabs/home.dart';
import 'tabs/sort.dart';
import './tabs/settings.dart';
import './tabs/mine.dart';
import './tabs/message.dart';
import 'package:flutter/material.dart';

class Tabs2 extends StatefulWidget {
  const Tabs2({super.key});

  @override
  State<Tabs2> createState() => _Tabs2State();
}

class _Tabs2State extends State<Tabs2> {
  int _currIndex = 0;

  final List<Widget> _pages = const [
    HomePage(),
    Sort(),
    Message(),
    Setting(),
    Mine(),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("P34 35")),

      body: _pages[_currIndex],
      bottomNavigationBar: BottomNavigationBar(
          showSelectedLabels: true,
          showUnselectedLabels: true,
          iconSize: 35,
          type: BottomNavigationBarType
              .fixed, //图标文字固定大小，BottomNavigationBarType.shifting选中的菜单图标文字会放大
          unselectedItemColor: Colors.grey,
          currentIndex: _currIndex,
          onTap: (index) {
            setState(() {
              //执行setState会执行build
              _currIndex = index; //切换选中页
            });
          },
          items: const [
            BottomNavigationBarItem(icon: Icon(Icons.home), label: "首页"),
            BottomNavigationBarItem(icon: Icon(Icons.category), label: "分类"),
            BottomNavigationBarItem(icon: Icon(Icons.message), label: "消息"),
            BottomNavigationBarItem(icon: Icon(Icons.settings), label: "设置"),
            BottomNavigationBarItem(icon: Icon(Icons.person), label: "用户"),
          ]),
      floatingActionButton: Container(
        margin: const EdgeInsets.only(top: 4), //调整FloatingActionButton的位置
        height: 80, //调整FloatingActionButton的大小
        width: 80,
        decoration: BoxDecoration(
            color: Colors.white, borderRadius: BorderRadius.circular(100)),
        padding: const EdgeInsets.all(10),
        child: FloatingActionButton(
            backgroundColor: _currIndex == 2 ? Colors.yellow : Colors.blue,
            shape: const CircleBorder(),
            child: const Icon(Icons.add),
            onPressed: () {
              setState(() {
                //执行setState会执行build
                _currIndex = 2; //切换选中页
              });
            }),
      ),

      floatingActionButtonLocation:
          FloatingActionButtonLocation.centerDocked, //配置浮动按钮位置
    );
  }
}
